package cn.edu.scau.cmi.chenzehan.client;
import cn.edu.scau.cmi.chenzehan.combinationPattern.safeCombination.Composite;
import cn.edu.scau.cmi.chenzehan.combinationPattern.safeCombination.Person;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class CombinationPattern extends Application {

	private Button button1;
	private Button button2;
	private TextField in1;
	private TextField in2;
	private TextArea text;
	private Composite c = new Composite();
	
	@Override
	public void start(Stage primaryStage) throws Exception {
		Parent root = FXMLLoader.load(getClass().getResource("CombinationPattern.fxml"));
		button1 = (Button)root.lookup("#button1");
		button2 = (Button)root.lookup("#button2");
		in1 =  (TextField)root.lookup("#in1");
		in2 = (TextField)root.lookup("#in2");
	    text = (TextArea)root.lookup("#text");
		
		button1.setOnAction(e->{
			text.clear();
			Person person = new Person(in1.getText(),Integer.parseInt(in2.getText()));
			c.getOrganPerson().add(person);
			text.appendText("添加成功！\n");
		});
		button2.setOnAction(e->{
			text.appendText(c.print());
		});
		
		
		Scene scene = new Scene(root);
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
}
